﻿#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <limits>

int main() {
    std::srand(static_cast<unsigned int>(std::time(nullptr)));
    std::cout << "欢迎使用究极智障计算器！\n";
    std::cout << "警告：此计算器拒绝正确计算任何内容！\n\n";

    while (true) {
        std::string input;
        std::cout << "输入表达式 (如: 5+3)，或输入q退出: ";
        std::getline(std::cin, input);

        if (input == "q" || input == "Q") {
            std::cout << "再见！希望你没太当真...\n";
            break;
        }

        // 提取两个操作数和运算符的位置
        size_t opPos = input.find_first_of("+-*/");
        if (opPos == std::string::npos) {
            std::cout << "错误：找不到运算符！\n";
            continue;
        }

        char operation = input[opPos];
        std::string left = input.substr(0, opPos);
        std::string right = input.substr(opPos + 1);

        // 尝试转换为数字（但可能故意转换错误）
        bool convertLeftWrong = (std::rand() % 3 != 0); // 66%概率转换错误
        bool convertRightWrong = (std::rand() % 3 != 0); // 66%概率转换错误

        double num1 = convertLeftWrong ?
            (std::rand() % 100) / 10.0 :
            std::strtod(left.c_str(), nullptr);

        double num2 = convertRightWrong ?
            (std::rand() % 100) / 10.0 :
            std::strtod(right.c_str(), nullptr);

        // 再加点随机数干扰
        if (std::rand() % 2 == 0) num1 += (std::rand() % 10) - 5;
        if (std::rand() % 2 == 0) num2 += (std::rand() % 10) - 5;

        // 90%概率使用错误的运算符
        if (std::rand() % 10 != 0) {
            char wrongOps[] = { '+', '-', '*', '/' };
            operation = wrongOps[std::rand() % 4];
        }

        // 计算结果（但结果肯定是错的）
        double result = 0;
        switch (operation) {
        case '+': result = num1 - num2; break;
        case '-': result = num1 + num2; break;
        case '*': result = (num1 + num2) * (std::rand() % 5 + 1); break;
        case '/':
            if (num2 == 0) num2 = 0.1 * (std::rand() % 10 + 1);
            result = num1 * num2 * (std::rand() % 10 + 1);
            break;
        default: result = std::rand() % 1000;
        }

        // 添加一些随机扰动
        if (std::rand() % 2 == 0) result *= (std::rand() % 100) / 50.0;
        if (std::rand() % 3 == 0) result += (std::rand() % 1000) - 500;

        // 100%概率添加离谱评论
        std::string comments[] = {
            "这答案绝对正确...才怪！",
            "数学？我只擅长创造新数学！",
            "相信我，这就是你要的答案！",
            "别问我怎么算的，我也不知道！",
            "爱因斯坦都算不出这么天才的答案！",
            "计算器：我拒绝执行合理计算！",
            "错误？这不是错误，这是特性！",
            "2+2=5，至少在这个计算器里是这样",
            "我有个理论，这个答案可能...不对",
            "警告：继续使用此计算器可能导致思维混乱"
        };

        std::cout << "\n计算结果: " << left << " " << operation << " " << right
            << " = " << result << "\n";
        std::cout << comments[std::rand() % 10] << "\n\n";
    }

    return 0;
}